<template>
  <div class="divBox">
    <el-card class="box-card">
      <el-form inline size="small" @submit.native.prevent>
        <el-form-item class="el-form-item-align-right">
          <el-button icon="el-icon-circle-plus" size="mini" type="primary" @click="openEdit()"
                     v-has-permi="['admin:member:level:save']">添加
          </el-button>
        </el-form-item>
      </el-form>
      <el-table :data="listData.list" size="mini"
                :header-cell-style=" {fontWeight:'bold',background:'#f8f8f9',color: '#515a6e',height:'40px'}" border>
        <el-table-column align="center" label="ID" prop="id" width="120"></el-table-column>
        <el-table-column align="center" label="名称" prop="membershipName" min-width="150"/>
        <el-table-column align="center" label="福利内容" prop="membershipBenefits" min-width="130"/>
        <!--        <el-table-column align="center" label="描述内容" prop="content" min-width="130"/>-->
<!--        <el-table-column align="center" label="描述内容">-->
<!--          <template slot-scope="scope">-->
<!--            <div v-html="scope.row.content"></div>-->
<!--          </template>-->
<!--        </el-table-column>-->
        <el-table-column align="center" label="支付金额" prop="paymentAmount" min-width="130"/>
        <el-table-column align="center" label="抵用金值" prop="offsetAmount" min-width="130"/>
        <el-table-column align="center" label="益联券值" prop="voucher" min-width="130"/>
        <el-table-column align="center" label="创建时间" prop="createTime" min-width="150"/>
        <el-table-column align="center" label="更新时间" prop="updateTime" min-width="150">
        </el-table-column>
        <el-table-column label="操作" min-width="180" fixed="right" align="center">
          <template slot-scope="scope">
            <el-button icon="el-icon-edit" size="mini" type="primary" @click="openEdit(scope.row.id)"
                       v-has-permi="['admin:member:level:save']">编辑
            </el-button>
            <el-button icon="el-icon-delete" size="mini" type="danger" @click="handlerDelete(scope.row.id,0)"
                       v-has-permi="['admin:member:level:delete']">删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <el-dialog
        :visible.sync="editDialog.show"
        :title="editDialog.id? '编辑':'新增'"
        destroy-on-close
        :close-on-click-modal="false"
        top="10px"
        width="1200px">
      <edit
          v-if="editDialog.show"
          :id="editDialog.id"
          @hideEditDialog="hideEditDialog"
          ref="editForm"
      />
    </el-dialog>
  </div>
</template>

<script>
import edit from './edit'
import {deleteRow, list, updateStatus} from "@/api/member";
import {checkPermi} from "@/utils/permission";

export default {
  components: {edit},
  data() {
    return {
      listData: {list: [], count: 0},
      listPram: {
        keyword: '',
        page: 1,
        limit: 20,
      },
      editDialog: {
        show: false,
        id: null
      },
      tableLoading: false,
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    checkPermi,
    getList() {
      this.tableLoading = true
      list().then(res => {
        this.listData.list = res;
      }).finally(() => {
      })
      this.tableLoading = false;
    },
    openEdit(id = null) {
      this.editDialog.id = id;
      this.editDialog.show = true
    },
    handlerDelete(id, state) {
      this.$confirm('确认删除该数据吗？').then(() => {
        const loading = this.$loading({text: '删除中', background: 'rgba(255,255,255,.5)'})
        deleteRow({id, state}).then(() => {
          this.$message.success('删除成功')
          this.getList()
        }).finally(() => {
          loading.close()
        })
      })
    },
    hideEditDialog() {
      this.editDialog.show = false
      this.getList()
    },
    handleSizeChange(val) {
      this.listPram.limit = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.listPram.page = val
      this.getList()
    },
    handleStatusChange(status, id) {
      const loading = this.$loading({text: '更新中', background: 'rgba(255,255,255,.5)'})
      updateStatus(id, status).then(() => {
        this.$message.success('更新状态成功')
        this.getList()
      }).finally(() => {
        loading.close()
      })
    },
    resetQuery() {
      this.listPram.keyword = '';
      this.getList()
    }
  }
}
</script>

<style scoped lang="scss">

</style>
